home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Mac OS USB DDK_v1.0.1 / Examples / CompositeClassDriver / CompositeDriverDescription.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-03  |  6.3 KB  |  203 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CompositeDriverDescription.c
  3.  
  4.     Contains:    Composite Class Driver Definition Header
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "CompositeClassDriver.h"
  19. #include "CompositeClassVersion.h"
  20.  
  21. usbCompositePBStruct newInterfacesPB;
  22.  
  23.  
  24. OSStatus CompositeDriverInitInterface(
  25.             UInt32                         interfaceNum, 
  26.             USBInterfaceDescriptor        *interfaceDesc, 
  27.             USBDeviceDescriptor            *deviceDesc, 
  28.             USBDeviceRef                 device);
  29.  
  30. //------------------------------------------------------
  31. //
  32. //    This is the driver description structure that the expert looks for first.
  33. //  If it's here, the information within is used to match the driver
  34. //  to the device whose descriptor was passed to the expert.
  35. //    Information in this block is also used by the expert when an
  36. //  entry is created in the Name Registry.
  37. //
  38. //------------------------------------------------------
  39. USBDriverDescription    TheUSBDriverDescription = 
  40. {
  41.     // Signature info
  42.     kTheUSBDriverDescriptionSignature,
  43.     kInitialUSBDriverDescriptor,
  44.     
  45.     // Device Info
  46.     0,                                        // vendor = not device specific
  47.     0,                                        // product = not device specific
  48.     0,                                        // version of product = not device specific
  49.     0,                                        // protocol = not device specific
  50.     
  51.     // Interface Info    (* I don't think this would always be required...*)                
  52.     0,                                        // Configuration Value
  53.     0,                                        // Interface Number
  54.     0,                                        // Interface Class
  55.     0,                                         // Interface SubClass
  56.     0,                                        // Interface Protocol
  57.         
  58.     
  59.     // Driver Info
  60.     "\pUSBCompositeDevice",                    // Driver name for Name Registry
  61.     kUSBCompositeClass,                        // Device Class  (from USBDeviceDefines.h)
  62.     kUSBCompositeSubClass,                    // Device Subclass 
  63.     kCMPHexMajorVers, 
  64.     kCMPHexMinorVers, 
  65.     kCMPCurrentRelease, 
  66.     kCMPReleaseStage,                        // version of driver
  67.     
  68.     // Driver Loading Info
  69.     kUSBDoNotMatchInterface                    // Please don't load us as an interface driver.
  70. };
  71.  
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,                // Version of this structure
  75.     CompositeDriverValidateHW,                // Hardware Validation Procedure
  76.     CompositeDriverInitialize,                // Initialization Procedure
  77.     CompositeDriverInitInterface,            // Interface Initialization Procedure
  78.     CompositeDriverFinalize,                    // Finalization Procedure
  79.     CompositeDriverNotifyProc                // Driver Notification Procedure
  80. };
  81.  
  82. // hubDriverInitInterface function
  83. // Called to initialize driver for an individual interface - either by expert or
  84. // internally by driver
  85. OSStatus CompositeDriverInitInterface(
  86.             UInt32                         interfaceNum, 
  87.             USBInterfaceDescriptor        *interfaceDesc, 
  88.             USBDeviceDescriptor            *deviceDesc, 
  89.             USBDeviceRef                 device)
  90. {
  91. #pragma unused (interfaceNum)
  92. #pragma unused (interfaceDesc)
  93. #pragma unused (deviceDesc)
  94. #pragma unused (device)
  95.  
  96.     return (OSStatus)kUSBNoErr;
  97. }
  98.  
  99. OSStatus    CompositeDriverNotifyProc(UInt32     notification, void *pointer)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (notification)
  103.     return(kUSBNoErr);
  104. }
  105.  
  106. // Hardware Validation
  107. // Called upon load by Expert
  108. OSStatus CompositeDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
  109. {
  110. #pragma unused (device)
  111. #pragma unused (desc)
  112.  
  113.     return (OSStatus)kUSBNoErr;
  114. }
  115.  
  116. // Initialization function
  117. // Called upon load by Expert
  118. OSStatus     CompositeDriverInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc,  UInt32 busPowerAvailable)
  119. {
  120. #pragma unused (busPowerAvailable)
  121.  
  122.     // until we get going, it's okay to accept a call to finalize
  123.     newInterfacesPB.okayToFinalizeFlag = true;
  124.     DeviceInitialize(device, pDesc, busPowerAvailable);
  125.     return (OSStatus)kUSBNoErr;
  126. }
  127.  
  128. // Termination function
  129. // Called by Expert when driver is being shut down
  130. OSStatus CompositeDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  131. {
  132. #pragma unused (pDesc)
  133. UInt32 i;
  134. OSStatus myErr;
  135.  
  136.     // If all the interfaces have been examined and had their interface
  137.     // drivers loaded, then go ahead and removed them all
  138.     // otherwise just return with a device busy error code.
  139.     USBExpertStatus(newInterfacesPB.pb.usbReference, "\pComposite Driver: Finalize", newInterfacesPB.pb.usbStatus);
  140.     if (theDeviceRef == newInterfacesPB.deviceRef)
  141.     {
  142.         if (newInterfacesPB.okayToFinalizeFlag)
  143.         {
  144.             USBExpertStatus(newInterfacesPB.pb.usbReference, "\pComposite Driver: Removing Interface drivers & InterfaceRefs", newInterfacesPB.pb.usbStatus);
  145.             for (i=0; i < newInterfacesPB.interfaceCount; i++)
  146.             {
  147.                 USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[i]);
  148.                 InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
  149.                 newInterfacesPB.pb.usbRefcon = 0;             
  150.                 newInterfacesPB.pb.usbWIndex = i;
  151.                 newInterfacesPB.pb.usbCompletion = (USBCompletion)-1;
  152.                 myErr = USBDisposeInterfaceRef(&newInterfacesPB.pb);
  153.             }
  154.             
  155.             InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
  156.             newInterfacesPB.pb.usbRefcon = 0;             
  157.             newInterfacesPB.pb.usbBuffer = newInterfacesPB.pFullConfigDescriptor;        
  158.             newInterfacesPB.pb.usbCompletion = (USBCompletion)-1;
  159.             myErr = USBDeallocMem(&newInterfacesPB.pb);
  160.             return (OSStatus)kUSBNoErr;
  161.         }
  162.         else
  163.         {
  164.             return (OSStatus)kUSBDeviceBusy;
  165.         }
  166.     }
  167.     else
  168.     {
  169.         USBExpertFatalError(newInterfacesPB.pb.usbReference, kUSBInternalErr, "\pComposite Driver - Finalize received unknown deviceRef", newInterfacesPB.pb.usbRefcon);
  170.         return (OSStatus)kUSBUnknownDeviceErr;
  171.     }
  172. }
  173.  
  174. void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
  175. {
  176. static Boolean beenThereDoneThat = false;
  177.  
  178.     if(beenThereDoneThat)
  179.     {
  180.         USBExpertFatalError(device, kUSBInternalErr, "\pComposite driver is not reentrant!", 0);
  181.         return;
  182.     }
  183.     beenThereDoneThat = true;
  184.     newInterfacesPB.okayToFinalizeFlag = false;
  185.     
  186.     newInterfacesPB.deviceRef = device;    
  187.     newInterfacesPB.deviceDescriptor = *pDeviceDescriptor;    
  188.     
  189.     newInterfacesPB.busPowerAvailable = busPowerAvailable;                            
  190.     newInterfacesPB.delayLevel = 0;                            
  191.     newInterfacesPB.transDepth = 0;                            
  192.     newInterfacesPB.retryCount = kCompositeRetryCount;
  193.     newInterfacesPB.pFullConfigDescriptor = nil;
  194.     
  195.     InitParamBlock(device, &newInterfacesPB.pb);
  196.     newInterfacesPB.pb.usbRefcon = kGetFullConfiguration0;            /* Start out at first state */
  197.     
  198. //    DebugStr("\pIn Composite Driver");
  199.     CompositeDeviceInitiateTransaction(&newInterfacesPB.pb);
  200. }
  201.  
  202.  
  203.